<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace plugins\crawler\controller; //Demo插件英文名，改成你的插件英文就行了

use cmf\controller\PluginAdminBaseController;
use think\Db;

use plugins\crawler\model\CrawlerCollectionModel;
use plugins\crawler\model\CrawlerSiteModel;

class AdminCollectionController extends PluginAdminBaseController
{

    protected function _initialize()
    {
        parent::_initialize();
        $adminId = cmf_get_current_admin_id();//获取后台管理员id，可判断是否登录
        if (!empty($adminId)) {
            $this->assign("admin_id", $adminId);
        }
    }

    /**
     * 采集插件规则
     * @adminMenu(
     *     'name'   => '采集规则',
     *     'parent' => 'admin/Plugin/default',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '采集规则',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $crawlerSiteId      = $this->request->param('crawler_site_id', 0, 'intval');
        $crawlerCollectionModel = new CrawlerCollectionModel();
        $crawlerSiteModel = new CrawlerSiteModel();

        $site = $crawlerSiteModel->find($crawlerSiteId);

        //category
        $collections = $crawlerCollectionModel
            ->where(['crawler_site_id' => $crawlerSiteId])
            ->paginate(15);
        
        // 获取分页显示
        $page = $collections->render();

        //var_dump($rules[0]->category);die;

        //$sites = Db::name("crawler_site")->all();
        //$demos = PluginDemoModel::all();

        // print_r($demos);

        $this->assign("collections", $collections);
        $this->assign("page", $page);
        
        $this->assign("siteid", $crawlerSiteId);
        $this->assign("site", $site);

        return $this->fetch('/admin_collection');
    }


}
